#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define l '\n'
#define M7md std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int main() {
M7md//When I wrote this code, only God and I understood what I did. Now only God knows//
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
string X,Y;
cin>>X>>Y;
vector<int>L(26),R(26);
for(auto j:X){
L[j-'A']++;
}
for(auto j:Y){
R[j-'A']++;
}
vector<int>S(26),P;
int SS=0;
for(int j=0;j<26;j++){
if(R[j]>L[j]) {
for(int k=0;k<abs(L[j]-R[j]);k++){
P.push_back(j);
}
SS+=abs(L[j]-R[j]);
}
}
cout<<SS<<"\n";
SS=0;
for(int j=0;j<X.size();j++){
int chart=X[j]-'A';
if(R[chart]<L[chart]){
if(P[SS]<=chart||L[chart]-S[chart]==L[chart]-R[chart]){
X[j]=char(P[SS]+'A');
--L[chart];
++L[P[SS]];
++SS;
}
else
S[chart]++;
}
else
S[chart]++;
}
cout<<X;
}
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |
Going to office | Color the boxes |